package design.structure_bridge;

import org.junit.Test;

/**
 * 桥接模式
 */
public class BridgeDemo {
    @Test
    public void test() {
        Brush brush=new LargeBrush(new BlackInl());
        brush.write();
        brush=new LargeBrush(new RedInl());
        brush.write();
    }

    //毛笔类
    public interface Brush{
        void write();
    }
    //墨水类
    public interface Ink{
        void fill();
    }

    public class LargeBrush implements Brush{
        private Ink ink;
        public LargeBrush(Ink ink) {
            this.ink = ink;
        }
        @Override
        public void write() {
            ink.fill();
            System.out.println("大号字");
        }
    }
    public class SmallBrush implements Brush{
        private Ink ink;
        public SmallBrush(Ink ink) {
            this.ink = ink;
        }
        @Override
        public void write() {
            ink.fill();
            System.out.println("小号字");
        }
    }

    public class RedInl implements Ink{
        @Override
        public void fill() {
            System.out.print("红色");
        }
    }
    public class BlackInl implements Ink{
        @Override
        public void fill() {
            System.out.print("黑色");
        }
    }


}
